#ifndef _TEMPLATE_SINGLETON_HPP_
# define _TEMPLATE_SINGLETON_HPP_

# include <cstdlib>

# include "Template/Utils/Traits.hpp"

namespace	Pattern
{
  template<typename T>
  class		Singleton
  {
  public:
    typedef typename Utils::Traits<T>::Type	Type;


  public:
    static Type		&GetInstance()
    {
      if (_Instance == NULL)
		_Instance = new Type;
      return (*_Instance);
    }

    static void		DeleteInstance()
    {
      if (_Instance != NULL)
		{
		  delete _Instance;
		  _Instance = NULL;
		}
    }

  protected:
    explicit Singleton() {}

    virtual ~Singleton() throw() {}



  protected:
    static Type		*_Instance;
  };
}

# define SingletonInit(T)	template<> Utils::Traits<T>::Type *Pattern::Singleton<T>::_Instance = NULL
# define SingletonClass(T)	friend class Pattern::Singleton<T>
# define SingletonDelete(T)	T::DeleteInstance()

#endif
